package com.sy.cloud.guess.controller;

import com.alibaba.fastjson.JSONObject;
import com.sy.common.model.Juejinuser;
import com.sy.common.service.IBaseService;
import com.sy.common.service.IDbService;
import com.sy.common.service.ITestService;
import com.sy.shiro.UsernameToken;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * Created by mac on 2018/1/8.
 */
@Controller
@Slf4j
@RequestMapping("/user")
public class UserController {
    @Resource
    private IDbService dbService;

    @Resource
    private IBaseService baseService;

    @Resource
    private ITestService testService;

    /*
    *
    * 绑卡接口
    * */
    @RequestMapping(value = "/bindcard", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ResponseBody
    public JSONObject bindcard(HttpServletRequest request) throws IOException {
        JSONObject result = new JSONObject();

        UsernameToken usernameToken = testService.getUser();
        if( usernameToken == null ){
            result.put( "status", "0" );
            result.put( "message", "没有登录");
            return result;
        }

        Juejinuser juejinuser = testService.getJueUserById( testService.getUser().getUserId().toString() );
        String cardnum = request.getParameter("cardnum");
        String username = request.getParameter( "name" );
        String idcard = request.getParameter("idcard"); // 身份证
        String phone = request.getParameter("phone");



        if( cardnum != null  ){
        }else{
            result.put( "status", "0" );
            result.put( "message", "银行卡号不能为空");
            return result;
        }

        if( username != null ){
        }else{
            result.put( "status", "0" );
            result.put( "message", "真实姓名不能为空");
            return result;
        }

        if( idcard != null ){
        }else{
            result.put( "status", "0" );
            result.put( "message", "身份证不能为空");
            return result;
        }

//        if( phone.length() == 0 ){
//            result.put( "status", "3" );
//            result.put( "message", "电话号码不能为空");
//            return result;
//        }


        juejinuser.setCard_num( cardnum );
        juejinuser.setReal_name( username );
        juejinuser.setId_number( idcard );
        juejinuser.setIfbind( 1 );

        baseService.update( juejinuser );
        result.put( "status", "1" );
        result.put( "message", "成功");
        return result;
    }
}
